<template>
  <view class="goods-detail">
    <image class="good-pic" :src="good.goods_pic" mode="aspectFit"></image>
    <view class="goods-info">
      <view class="goods-name">{{ good.goods_name }}</view>
      <view class="goods-sku">
        <view
          style="
            font-size: 20rpx;
            color: #8c8c8c;
            margin-right: 20rpx;
            display: inline-block;
          "
          v-for="(attr, attr_index) in good.attr_list"
          :key="attr_index"
        >
          {{ attr.attr_group_name }}：{{ attr.attr_name }}
        </view>
      </view>
      <view class="goods-price">
        <view class="price">
          <text>￥</text>
          <text>{{ good.price | priceBeforeZero }}</text>
          <text>{{ good.price | priceAfterZero }}</text>
        </view>
        <view class="number">x{{ good.num }}</view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {};
  },
  props: {
    good: {
      type: Object,
      default: {},
    },
  },
  filters: {
    priceBeforeZero(val) {
      if (val.indexOf(".") < 0) return `${val}.`;
      return val.substr(0, val.indexOf("."));
    },
    priceAfterZero(val) {
      if (val.indexOf(".") < 0) return "00";
      return val.substr(val.indexOf("."), val.lenhth);
    },
  },
  computed: {},
  methods: {},
};
</script>

<style lang="scss"scoped>
.goods-detail {
  display: flex;
  justify-content: flex-start;
  align-items: center;

  .good-pic {
    width: 200rpx;
    height: 200rpx;
    border-radius: 10rpx;
    margin-right: 25rpx;
  }

  .goods-info {
    max-width: 474rpx;

    .goods-name {
      font-size: 24rpx;
      font-family: PingFang SC;
      font-weight: 400;
      color: #262626;
      line-height: 44rpx;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
    }

    .goods-sku {
      font-size: 20rpx;
      font-family: PingFang SC;
      font-weight: 400;
      color: #8c8c8c;
      line-height: 26rpx;
      margin: 16rpx 0;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .goods-price {
      line-height: 44rpx;
      display: flex;
      justify-content: space-between;

      .price {
        display: flex;
        align-items: baseline;
        color: #f7271f;
        font-weight: 500;

        text:nth-child(1) {
          font-size: 20rpx;
        }
        text:nth-child(2) {
          font-size: 34rpx;
        }
        text:nth-child(3) {
          font-size: 20rpx;
        }
      }
    }
  }
}
</style>
